* Created by wl
* 项目管理>持有中-详情页-投资服务-添加投资动态信息
*/
<template>
    <div v-if="dialogVisible">
        <el-dialog 
            title="添加服务动态" 
            :visible.sync="dialogVisible"
            :show-close="false">
            <el-form :model="itemHoldService">
                <el-row>
                    <el-col :span='10'>
                        <el-form-item label="服务类型" :label-width="formLabelWidth">
                            <el-select v-model="itemHoldService.serviceType" placeholder="请选择">
                                <el-option v-for="item in serviceType" :label="item.name" :value="item.id"
                                        :key="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span='10'>
                        <el-form-item label="服务时间" :label-width="formLabelWidth">
                            <el-date-picker type="date" v-model="itemHoldService.serviceTime" placeholder="选择日期"
                                            format="yyyy-MM-dd"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item label="服务主题" :label-width="formLabelWidth">
                    <el-input auto-complete="off" v-model="itemHoldService.title" :maxlength="300"></el-input>
                </el-form-item>
                </el-form-item>
                <el-form-item label="内容记录" :label-width="formLabelWidth">
                    <el-input type="textarea" :rows="5" v-model="itemHoldService.serviceRecord" :maxlength="3000" placeholder="请输入内容">
                    </el-input>
                </el-form-item>
                <csSimple :fileType="fileType" :getFileUploadedReturnData="getFileUploadedReturnDataFun" :deleteFileId="deleteId" :isShowSelect="false" :labelWidth="'120px'"></csSimple>
            </el-form>
            <span slot="footer" class="dialog-footer align-center">
                <el-button @click="close" size="small">取 消</el-button>
                <el-button type="primary" @click="save" size="small">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '../../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    export default {
        data() {
            return {
                fileType: '10052',
                formLabelWidth: '120px',
                dialogShow: false,
                serviceType: this.$store.state.user.dictionaryMap.itemServiceType,
                fileIds: [], //文件记录
                itemHoldService: {
                    id: '', // id
                    itemId: this.$route.params.itemId, // 项目ID ,
                    serviceRecord: '', // 服务记录 ,
                    serviceTime: '', // 服务时间 ,
                    serviceType: '', // 服务类型 字典 itemServiceType ,
                    title: '', // 标题
                },
            }
        },
        watch: {
        },
        props: {
            dialogVisible: {
                type: Boolean,
                default: function () {
                    return false;
                }
            },
        },
        created() {
        },
        mounted() {
        },
        methods: {
            close() {
                this.$emit('close')
                this.init()
            },
            save() {
                let query = {
                    fileIds: this.fileIds,
                    itemHoldService: this.itemHoldService,
                    itemId: this.$route.params.itemId,
                }
                apiHttp(api.EDIT_SERVICE, query).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: '数据添加成功！',
                            type: 'success',
                            center: true
                        });
                        this.$emit('save')
                        this.init()
                    }
                })
            },
            init() {
                this.fileIds = [] //文件记录
                this.itemHoldService.id = '' // id
                this.itemHoldService.itemId = this.$route.params.itemId // 项目ID ,
                this.itemHoldService.serviceRecord = '' // 服务记录 ,
                this.itemHoldService.serviceTime = '' // 服务时间 ,
                this.itemHoldService.serviceType = '' // 服务类型 字典 itemServiceType ,
                this.itemHoldService.title = '' // 标题
            },
            //获取
            async getPartnerDetail() {
                let {resCode, data} = await apiHttp(api.CHECK_SERVICE, {itemId: this.$route.params.itemId});
                if (resCode === STATUS_HTTP_SUCCESS) {
                    this.serviceList = data.itemHoldServiceVO
                }
            },
            getFileUploadedReturnDataFun(data) {
                data.map (item => {
                    this.fileIds.push(item.id)
                })
            },
            deleteId(id) {
                this.fileIds.map((item,index)=> {
                    if (item === id) {
                        this.fileIds.splice(index,1)
                    }
                })
            }
        },
        components: {
            csUpload: require('__components/upload-btn/index'),
            csSimple: require('__components/file-list/simple'),
        },
    }
</script>
